package com.demo.controller;

import cn.hutool.core.util.ObjectUtil;
import com.demo.beans.ReturnData;
import com.demo.beans.User;
import com.demo.utils.UserThreadLocal;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;

@RestController
@RequestMapping("/")
public class IndexController {
    @RequestMapping("excel")
    public ModelAndView toIdex(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("sys/schoolPlan");
        return modelAndView;
    }

    @RequestMapping("permission")
    public ModelAndView toPerssion(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("sys/user-manage");
        return modelAndView;
    }

    @RequestMapping("getNav")
    public ModelAndView getNav(String menuAction){
        ModelAndView modelAndView = new ModelAndView();
        if ("schoolPlan".equals(menuAction)){
            modelAndView.setViewName("sys/schoolPlan");
        }
        if("user-manage".equals(menuAction)){
            modelAndView.setViewName("sys/user-manage");
        }
        if("menu-manage".equals(menuAction)){
            modelAndView.setViewName("sys/menu-manage");
        }
        if("clock".equals(menuAction)){
            modelAndView.setViewName("sys/clock");
        }
        if("music-player".equals(menuAction)){
            modelAndView.setViewName("sys/music-player");
        }
        return modelAndView;
    }

    @RequestMapping("login")
    public ModelAndView toLogin(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("sys/login");
        return modelAndView;
    }
    @RequestMapping("Search")
    public ModelAndView toPasswordSearch(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("sys/Search");
        return modelAndView;
    }
    @RequestMapping("secret")
    public ModelAndView toSecretPage(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("mine/Secret");
        return modelAndView;
    }
    //导航页面
    @RequestMapping("nav")
    public ModelAndView toNavPage(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("sys/navigation");
        return modelAndView;
    }
    //音乐播放页面
    @RequestMapping("music")
    public ModelAndView toMusicPlayer(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("sys/music-player");
        return modelAndView;
    }

    @RequestMapping("menu")
    public ModelAndView toMenuPage(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("sys/menu-manage");
        return modelAndView;
    }
    public boolean isLogin(){
        User user = UserThreadLocal.get();
        if (ObjectUtil.isNotEmpty(user)){
            return true;
        }
        return false;
    }
    @RequestMapping("islogin")
    public ReturnData idLogin(){
        ReturnData returnData = BaseAction.createReturnData();
        boolean login = isLogin();
        if (login){
            returnData.put("islogin","1");
        }else {
            returnData.put("islogin","0");
        }
        return returnData;
    }
}
